package service;

import dao.SysCountryDao;
import entity.SysCitys;
import entity.SysCountry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chris on 17-5-15.
 */
@Service
public class SysCountryService {
    @Autowired
    private SysCountryDao sysCountryDao;

    @Transactional(readOnly = true)
    public List<SysCountry> list(){
        String hql = "from SysCountry";
        return sysCountryDao.findList(hql);
    }

    @Transactional(readOnly = true)
    public Map<Integer,String> transMap(){
        String hql = "from SysCountry";
        List<SysCountry> countries = sysCountryDao.findList(hql);
        Map<Integer,String> maps = new HashMap<Integer,String>();
        for (SysCountry country : countries){
            maps.put(country.getId(),country.getName());
        }
        return maps;
    }

    /*
  * 根据id找出实体
  * */
    @Transactional(readOnly = true)
    public SysCountry FindCountryById(int id){
        return sysCountryDao.getById(id);
    }
}
